package com.ruoyi.quartz.task;

import com.ruoyi.cms.blog.domain.CmsAdvertised;
import com.ruoyi.cms.blog.mapper.CmsAdvertisedMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("topTask")
@Slf4j
public class TopTask {
    @Autowired
    private CmsAdvertisedMapper cmsAdvertisedMapper;

    public void start() {
        log.info("start the task");
        List<CmsAdvertised> list = cmsAdvertisedMapper.getTop();
        if (list.isEmpty()) {
            log.info("the eligible quantity is zero");
        }
        list.forEach(l -> {
            //CmsAdvertised cmsAdvertised = new CmsAdvertised();
            l.setTopMode(0).setUpdateTime(new Date());
            cmsAdvertisedMapper.update(l);
        });
    }
}
